/**
 * 任务详情页面时间显示修复脚本
 * 这个脚本包含需要添加到TaskDetailPage.tsx的关键代码片段
 */

// 1. 在任务加载时解析时间字段（已完成）
const parseTaskTime = `
// 如果dueDate包含时间信息，则分离日期和时间
if (foundTask.dueDate && foundTask.dueDate.includes('T')) {
  const dateTime = new Date(foundTask.dueDate)
  if (!isNaN(dateTime.getTime())) {
    dueDate = dateTime.toISOString().split('T')[0] // YYYY-MM-DD
    dueTime = dateTime.toTimeString().slice(0, 5) // HH:mm
  }
}

const taskWithDefaults = {
  ...foundTask,
  dueDate,
  dueTime,
  reminderMinutes: (foundTask as any).reminder_minutes || (foundTask as any).reminderMinutes || 30,
  subtasks: (foundTask as any).subtasks || [],
  tags: (foundTask as any).tags || []
}
`

// 2. 提醒设置显示组件
const reminderSettingsDisplay = `
{/* 提醒设置 */}
{task.dueDate && (
  <div className="flex items-center gap-3 p-3 bg-theme-bg-secondary rounded-xl">
    <Calendar size={18} className="text-theme-text-muted flex-shrink-0" />
    <div className="flex-1 min-w-0">
      <div className="text-xs text-theme-text-muted mb-1">提醒设置</div>
      {isEditing ? (
        <div className="space-y-2">
          <div className="text-xs text-theme-text-muted">提前多长时间提醒</div>
          <div className="grid grid-cols-2 gap-1">
            {[5, 15, 30, 60, 120, 1440].map((minutes) => (
              <button
                key={minutes}
                onClick={() => setEditingTask(prev => prev ? ({ ...prev, reminderMinutes: minutes }) : null)}
                className={\`px-2 py-1 rounded text-xs font-medium transition-all \${
                  editingTask?.reminderMinutes === minutes
                    ? 'bg-blue-500 text-white'
                    : 'bg-theme-bg border border-theme-border text-theme-text hover:bg-blue-50'
                }\`}
              >
                {minutes < 60 ? \`\${minutes}分钟\` : minutes === 60 ? '1小时' : minutes === 120 ? '2小时' : '1天'}
              </button>
            ))}
          </div>
        </div>
      ) : (
        <div className="text-sm font-medium text-theme-text">
          提前 {task.reminderMinutes && task.reminderMinutes < 60 ? \`\${task.reminderMinutes}分钟\` : 
                task.reminderMinutes === 60 ? '1小时' : 
                task.reminderMinutes === 120 ? '2小时' : 
                task.reminderMinutes === 1440 ? '1天' : 
                '30分钟'} 提醒
        </div>
      )}
    </div>
  </div>
)}
`

// 3. 保存时合并日期和时间
const saveTaskWithTime = `
const handleSave = async () => {
  if (!editingTask) return

  try {
    // 合并日期和时间
    let fullDateTime = editingTask.dueDate
    if (editingTask.dueDate && editingTask.dueTime) {
      fullDateTime = \`\${editingTask.dueDate}T\${editingTask.dueTime}:00.000Z\`
    }

    const taskData = {
      ...editingTask,
      dueDate: fullDateTime,
      reminderMinutes: editingTask.reminderMinutes || 30
    }

    await taskAPI.updateTask(task.id, taskData)
    await loadTask() // 重新加载任务
    setIsEditing(false)
    setEditingTask(null)
  } catch (error) {
    console.error('保存任务失败:', error)
  }
}
`

console.log('任务详情页面时间显示修复代码片段已准备')
console.log('需要手动将这些代码片段集成到 TaskDetailPage.tsx 中')
